from machine import UART
from machine import FPIOA

fpioa=FPIOA()

fpioa.set_function(11,FPIOA.UART2_TXD)
fpioa.set_function(12,FPIOA.UART2_RXD)

uart=UART(2,baudrate=115200,bits=UART.EIGHTBITS,parity=UART.PARITY_NONE,stop=UART.STOPBITS_ONE)

#发送字符串
uart.write("hello\r\n")
#发送数组(必须为bytes数组)
Array=bytes([1,2,3])
uart.write(Array)

#接受函数
data=None
while data==None:
    data=uart.read()

#读取一行，以换行符为结尾
String=""
while String=="":
    String=uart.readline()

#将数据存入缓冲区
buffer=bytearray(10)
bytes_received=0
while bytes_received==0:
    bytes_received=uart.readinto(buffer)







